import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import plugins from "@/plugins";
import '@arco-design/web-vue/dist/arco.css';
import Local from "@/utils/local";
import { buildRoutes, getToken } from "@/utils";
import { getUserMenuList } from "@/services/menuApi.ts";
import "quill/dist/quill.core.css"
import "quill/dist/quill.snow.css"
import "quill/dist/quill.bubble.css"
Local.localSave('language', 'zh')

function main() {
    const app = createApp(App)

    app.use(plugins)

    app.mount('#app')
}

function LoginInit() {
    const role = localStorage.getItem("teacher")
    
    
    if (role) {
        main()
    
    } else {
        getUserMenuList().then(res => {
            if (res.code === 200) {
                Local.localSave(
                    "menuList",
                    JSON.stringify(res.data)
                );
                buildRoutes(res.data)
                main()
            }
        })
    }
   
}

const token = getToken()
if (token) {
    LoginInit()
} else {
    main()
}
